package gamesrv.history;

import gamesrv.history.api.HistoryService;
import gamesrv.history.impl.HistoryServiceImpl;

import org.hibernate.SessionFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;




public class Activator implements BundleActivator {
	SessionFactory sessionFactory;
	
	ServiceRegistration<?> srvToken;
		
	
	
	@SuppressWarnings("deprecation")
	public void start(BundleContext context) throws Exception {
		System.out.println("History service: starting..");
					
		sessionFactory = new org.hibernate.cfg.Configuration()
        .configure()        
        .buildSessionFactory();
		
		HistoryService historyService = new HistoryServiceImpl(sessionFactory);
		
		srvToken = context.registerService(HistoryService.class, historyService, null);
		System.out.println("History service: started.");
	}
	
	
	public void stop(BundleContext context) throws Exception {
		System.out.println("History service: stopping..");
		srvToken.unregister();
		sessionFactory.close();
		System.out.println("History service: stopped..");
	}

}
